Place civil cell
The below code shows placing the civil cells using
alignments. Here in below example only one alignment is considered. The number
of alignments depends on civil cell to be placed.
//Required references
using System.Collections.Generic;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.SDK.Edit;
public bool PlaceCivilCell()
{
//Get connection to current document
ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
//Get active geometric model
GeometricModel gm = con.GetActiveGeometricModel();
if (gm == null)
{
con.Close();
con.Dispose();
return false;
}
//Civil cell name
string civilCellToPlace = "Basin";
Bentley.CifNET.GeometryModel.SDK.CivilCellInfo sourceCivil = new Bentley.CifNET.GeometryModel.SDK.CivilCellInfo();
//Get all the civil cells from the available DGNLib's
IEnumerable<Bentley.CifNET.GeometryModel.SDK.CivilCellInfo> libraryCivilCells = Bentley.CifNET.GeometryModel.SDK.CivilCell.GetCivilCellInfoFromLibraries();
//Get civil cell info having name equal to civilCellToPlace
foreach (var civilCell in libraryCivilCells)
{
if (civilCell.CivilCellName.ToString().Equals(civilCellToPlace))
{
sourceCivil = civilCell;
break;
}
}
List<KeyValuePair<Bentley.CifNET.GeometryModel.SDK.Alignment, bool>> alignmentsAndReverse = new List<KeyValuePair<Bentley.CifNET.GeometryModel.SDK.Alignment, bool>>();
//The number of alignments required to place cell varries based on which cell to place
foreach (Alignment alignment in gm.Alignments)
{
if (alignment != null && alignment.IsFinalElement)
{
KeyValuePair<Bentley.CifNET.GeometryModel.SDK.Alignment, bool> elePair = new KeyValuePair<Bentley.CifNET.GeometryModel.SDK.Alignment, bool>(alignment, true);
alignmentsAndReverse.Add(elePair);
break;
}
}
//Place civil cell
if (alignmentsAndReverse.Count > 0 && sourceCivil != null)
{
Bentley.CifNET.GeometryModel.SDK.CivilCell civilcell = gm.CreateCivilCellElement(sourceCivil, alignmentsAndReverse);
if (civilcell != null)
{
return true;
}
}
return false;
}